package cn.jofei.common.reflect;

import cn.jofei.core.Invoker;
import cn.jofei.core.bean.BeanFactory;
import cn.jofei.core.container.Container;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * ReflectionMethod
 *
 * @author Jofei Bao
 * @version ngbao v1.0.0
 * @date 2022年07月08日 23:26
 */
public class ReflectionMethod {

    private final String beanName;

    private final Method method;

    public ReflectionMethod(String beanName, Method method) {
        this.beanName = beanName;
        this.method = method;
    }

    public Method getMethod() {
        return method;
    }

    public Object execution(Object... o) {
        try {
            Object instance = BeanFactory.getBean(beanName);
            return method.invoke(instance, o);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
}
